const path = require("path");
const fs = require("fs");

const env = {};

Object.keys(process.env).map(key => {
  if (key.startsWith("VUE_APP")) {
    env[key] = process.env[key];
  }
});

fs.writeFileSync("src/env.json", JSON.stringify(env, null, 2), {
  encoding: "utf-8"
});

const miniprogramConfig = {
  origin: "https://www.kpan.cn",
  entry: "/home",
  router: {
    home: ["/home"],
    my: ["/my"],
    page: ["/page/(a|b)?"]
  },
  redirect: {
    notFound: "home",
    accessDenied: "home"
  },
  generate: {
    app: "default",
    appWxss: "default",
    autoBuildNpm: "yarn",
    tabBar: {
      color: "#8188A0",
      selectedColor: "#0250FF",
      backgroundColor: "#ffffff",
      list: [
        {
          pageName: "home",
          text: "首页",
          iconPath: path.resolve(__dirname, "./src/assets/tabbar/home.png"),
          selectedIconPath: path.resolve(
            __dirname,
            "./src/assets/tabbar/home-sel.png"
          )
        },
        {
          pageName: "my",
          text: "我的",
          iconPath: path.resolve(__dirname, "./src/assets/tabbar/my.png"),
          selectedIconPath: path.resolve(
            __dirname,
            "./src/assets/tabbar/my-sel.png"
          )
        }
      ]
    }
  },
  app: {
    backgroundTextStyle: "dark",
    navigationBarTextStyle: "white",
    navigationStyle: "default",
    navigationBarTitleText: "demo"
  },
  appExtraConfig: {
    sitemapLocation: "sitemap.json"
  },
  global: {
    share: true,
    windowScroll: false,
    backgroundColor: "#F7F7F7",
    rem: true
  },
  pages: {},
  optimization: {
    domSubTreeLevel: 10,

    elementMultiplexing: true,
    textMultiplexing: true,
    commentMultiplexing: true,
    domExtendMultiplexing: true,

    styleValueReduce: 5000,
    attrValueReduce: 5000
  },
  projectConfig: {
    appid: "wx58b37104366361cc",
    projectname: "kbone-demo"
  },
  packageConfig: {
    name: "kbone-demo"
  },
  // vue-cli 相关配置
  vue: {
    entryFileName: "main.mp.ts",
    cdnPath: "/",
    cdnLimit: 10240
  }
};

module.exports = miniprogramConfig;
